package org.cy.example.ui

import android.os.Bundle
import android.widget.Toast
import com.alibaba.fastjson.JSON
import org.cy.evolution.framework.ui.BaseActivity
import org.cy.evolution.ioc.injector.EvolutionInjection
import org.cy.evolution.ioc.annotation.AutoInject
import org.cy.evolution.net.http.exception.ApiException
import org.cy.example.R
import org.cy.example.domain.entity.ExamEntity
import org.cy.example.mvp.ExamContract
import org.cy.example.mvp.ExamPresenter

class MainActivity : BaseActivity(), ExamContract.IExamView {

    @AutoInject
    lateinit var examPresenter : ExamPresenter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        EvolutionInjection.inject<MainActivity>(this)

        setContentView(R.layout.activity_main)
        examPresenter.onAttach(this)
        examPresenter.getExamData()
    }

    override fun onDestroy() {
        super.onDestroy()
        examPresenter.onDetach()
        EvolutionInjection.destroy<MainActivity>(this)
    }

    override fun onLoadExamDataSuccess(lstData: List<ExamEntity>) {
        Toast.makeText(this, JSON.toJSONString(lstData), Toast.LENGTH_LONG).show()
    }

    override fun onShowLoading(type: Int) {

    }

    override fun onHideLoading(type: Int) {

    }

    override fun onShowError(type: Int, aex: ApiException?) {

    }
}
